function* idMaker(){
  var index = 0;
  while(index < 3){
    yield index++;
  }
}
var gen = idMaker();
console.log(gen.next().value)

function delay(time, callback){
  setTimeout(function(){
    callback("slept for " + time)
  }, time)
}

function run(generatorFunc){
  var generatorItr = generatorFunc(resume);
  function resume(callbackValue){
    generatorItr.next(callbackValue);
  }
  generatorItr.next()
}

run(function* myDelayedMessages(resume){
  console.log(yield delay(1000, resume));
  console.log(yield delay(1200, resume));
})
